package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiShowYongJin;
import com.zcx.helper.app.AppCallBack;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.math.BigDecimal;

/**
 * Created by Administrator on 2016/5/20.
 */
public class CommissionActivity extends BaseActivity implements View.OnClickListener {


    private TextView commission_can_tv;
    private TextView commission_had_tv;

    private GetApiShowYongJin getApiShowYongJin = new GetApiShowYongJin(new AsyCallBack<GetApiShowYongJin.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiShowYongJin.Info info) throws Exception {

            BigDecimal extract = new BigDecimal(info.data.extract).setScale(2);
            BigDecimal extracted = new BigDecimal(info.data.extracted).setScale(2);

            commission_can_tv.setText(extract.toString() + "元");
            commission_had_tv.setText(extracted.toString() + "元");

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commission);

        //可提现佣金  已提现佣金
        commission_can_tv = ((TextView) findViewById(R.id.commission_can_tv));
        commission_had_tv = ((TextView) findViewById(R.id.commission_had_tv));

        getApiShowYongJin.userid = BaseApplication.BasePreferences.readUserId();
        getApiShowYongJin.execute(this);


        setAppCallBack(new RefreshCommissionCallback());

    }

    @Override
    public void onClick(View view) {

        Intent intent = null;

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.commission_can_rl:
                intent = new Intent(this, CommissionCanWithdrawActivity.class);
                break;

            case R.id.commission_had_rl:
                intent = new Intent(this, CommissionHasWithdrawalActivity.class);
                break;

            case R.id.commission_introduce_rl:
                intent = new Intent(this, CommissionIntroduceActivity.class);
                break;

        }

        startActivity(intent);

    }


    public class RefreshCommissionCallback implements AppCallBack {


        public void refreshCommission() {

            getApiShowYongJin.userid = BaseApplication.BasePreferences.readUserId();
            getApiShowYongJin.execute(CommissionActivity.this);
        }

    }


}
